package webone.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import webone.context.MyUserInfoContext;
import webone.javabean.OnlineUserInfo;

@WebListener
public class WebSessionListener implements HttpSessionListener {

	public WebSessionListener() {
	}

	private MyUserInfoContext myc = MyUserInfoContext.getInstance();

	public void sessionCreated(HttpSessionEvent httpSessionEvent) {
		HttpSession session = httpSessionEvent.getSession();
		OnlineUserInfo userInfo = new OnlineUserInfo();
		userInfo.setSessionid(session.getId());
		userInfo.setSession(session);
		//System.out.println(userInfo);
		myc.addUserInfoContext(userInfo);
		System.out.println(myc.getOnlineUserInfoMap());
	}

	public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
		HttpSession session = httpSessionEvent.getSession();
		myc.delUserInfoContext(session.getId());
	}
}
